package com.v5.mr.mutiltable;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class MutilTableQueryReducer extends Reducer<LongWritable,Text, Text, Text> {

	@Override
	protected void reduce(LongWritable k3, Iterable<Text> v3, Context context)
			throws IOException, InterruptedException {
		//定义变量保存部门名称、员工姓名
		String dname = "";
		String empNameList = "";
		
		for(Text t:v3){
			String str = t.toString();
			
			//找到*号的位置
			int index = str.indexOf("*");
			if(index >=0){
				//代表部门名称
				dname = str.substring(1);
			}else{
				//代表员工姓名
				empNameList = str + ";"+empNameList;
			}
		}		
		
		//输出
		context.write(new Text(dname), new Text(empNameList));
	}
}
